<template>
	<view>
		<my-search bgColor="#13227a" :radius="15" placeholder="默认的 placeholder 值" @click="gotoSearch" />
		<view class="scroll-view-container">
			<scroll-view scroll-y class="left-scroll-view" :style="{ height: wh + 'px' }">
				<block v-for="(item, index) in cateList" :key="index">
					<view :class="['left-scroll-view-item', index === active ? 'active' : '']"
					       @click="activeChanged(index)">{{ item.cat_name}}</view>
				</block>
			</scroll-view>
			<scroll-view scroll-y :scroll-top="scrollTop" class="right-scroll-view" :style="{ height: wh + 'px' }">
				<view class="cate-leve" v-for="(item, index) in cateLeve" :key="index">
					<view class="cate-leve-title">/{{ item.cat_name }}/</view>
					<view class="cate-leves-list">
						<view class="cate-leves-item" v-for="(items, indexs) in item.children" :key="indexs"
						        @click="gotoGoodsList(items)">
							<image :src="items.cat_icon" mode=""></image>
							<text>{{ items.cat_name }}</text>
						</view>
					</view>
				</view>
			</scroll-view>
		</view>
	</view>
</template>

<script>
	import bedgeMix from '@/mixins/tabbar-badge.js'
	export default {
		mixins: [bedgeMix],
		data() {
			return {
				wh:0,
				cateList:[],
				cateLeve:[],
				active:0,
				scrollTop:0
			};
		},
		onLoad() {
			const sysInfo = uni.getSystemInfoSync()
			this.wh = sysInfo.windowHeight - 50
			this.getCateList()
		},
		methods:{
			async getCateList(){
				const { data: res } = await uni.$http.get('/api/public/v1/categories')
				if(res.meta.status !== 200) return uni.$showMsg()
				this.cateList = res.message
				this.cateLeve = res.message[0].children
			},
			activeChanged(index) {
				this.active = index
				this.cateLeve = this.cateList[index].children
				this.scrollTop = this.scrollTop === 0 ? 1 : 0
			} ,
			gotoGoodsList(item){
				uni.navigateTo({
					url:`/subpkg/goods_list/goods_list?${item.cat_id}`
				})
			},
			gotoSearch(){
				uni.navigateTo({
					url:'/subpkg/search/search'
				})
			}
		}
	}
</script>

<style lang="scss">
.scroll-view-container{
	display: flex;
	.left-scroll-view{
		width: 120px;
		.left-scroll-view-item {
			line-height: 60px;
			background-color: #F7F7F7;
			text-align: center;
			font-size: 12px;
			&.active {
				background-color: #ffffff;
				position: relative;
				&::before {
					content:'';
					display: block;
					width: 3px;
					height: 30px;
					background-color: #C00000;
					position: absolute;
					top: 50%;
					left: 0;
					transform: translateY(-50%);
				}
			}
		}
	}
	.cate-leve-title {
		font-size: 12px;
		font-weight: bold;
		text-align: center;
		padding: 15px 0 ;
	}
	.cate-leves-list {
		display: flex;
		flex-wrap: wrap;
		.cate-leves-item {
			width: 33.33%;
			margin-bottom: 10px;
			display: flex;
			flex-direction: column;
			align-items: center;
			
			image {
				width: 60px;
				height: 60px;
			}
			
			text {
				font-size: 12px
			}
		}
	}
}
</style>
